package com.dg.river.netty.axle.msg2dev;





import com.dg.river.core.util.DateUtils;

import java.util.Date;

/**
 * Created by zhangguohua on 2017/6/1.
 * 定义消息报文头
 */
public class DevMsgHead {
    /**
     * 报文标识，固定取值 0x70
     */
    private short msgFlag = 0x70;
    /**
     * 报文版本，取值0x01
     */
    private short version = 0x01;
    /**
     * 报文长度，网络字节序(包含Data数据长度+2字节校验码)
     */
    private long msgLen;

    /**
     * deviceId
     */
    private long deviceId;

    /**
     * 报文类型：
     */
    private short msgType;

    /**
     * 报文序列号，报文接收方按原值返回，可做合法性校验,每次发送报文后顺序增1.
     */
    private short msgId;

    /**
     * 发送时间
     */
    private Date timestamp;


    public short getMsgFlag() {
        return msgFlag;
    }

    public void setMsgFlag(short msgFlag) {
        this.msgFlag = msgFlag;
    }

    public short getVersion() {
        return version;
    }

    public void setVersion(short version) {
        this.version = version;
    }

    public long getMsgLen() {
        return msgLen;
    }

    public void setMsgLen(long msgLen) {
        this.msgLen = msgLen;
    }

    public long getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(long deviceId) {
        this.deviceId = deviceId;
    }

    public short getMsgType() {
        return msgType;
    }

    public void setMsgType(short msgType) {
        this.msgType = msgType;
    }

    public short getMsgId() {
        return msgId;
    }

    public void setMsgId(short msgId) {
        this.msgId = msgId;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    @Override
    public String toString() {
        return String.format("{msgFlag=%02x, version=%d, msgLen=%d, deviceId=%d, msgType=%02x, msgId=%d, timestamp=%s}",
                msgFlag, version, msgLen, deviceId, msgType, msgId, DateUtils.formatDateTime(timestamp));
    }
}
